package com.example.weli.ble2test;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import java.io.InputStream;

public class Sorbutton extends View {
    int cX;
    int cY;
    Bitmap mBitmap_no;
    Bitmap mBitmap_to;
    private Paint mPaint;
    InputStream not;
    InputStream t;
    boolean toun = false;

    public Sorbutton(Context context) {
        super(context);
        initial_sor();
    }

    public Sorbutton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initial_sor();
    }

    public Sorbutton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initial_sor();
    }

    void initial_sor() {
        this.mBitmap_no = BitmapFactory.decodeResource(getResources(), R.drawable.gnot);
        this.mBitmap_to = BitmapFactory.decodeResource(getResources(), R.drawable.gt);
    }

    public boolean isOnTouch() {
        return this.toun;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction() & 255) {
            case joystick.COORDINATE_CARTESIAN /*0*/:
                this.toun = true;
                invalidate();
                break;
            case joystick.COORDINATE_DIFFERENTIAL /*1*/:
                this.toun = false;
                invalidate();
                break;
            case UIActivity.xconnected /*2*/:
                return false;
        }
        return true;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Matrix matrix = new Matrix();
        matrix.setRotate(90.0f);
        Bitmap resizedBitmap = null;
        if (this.toun) {
            resizedBitmap = Bitmap.createBitmap(this.mBitmap_to, 0, 0, 150, 150, matrix, true);
        } else if (!this.toun) {
            resizedBitmap = Bitmap.createBitmap(this.mBitmap_no, 0, 0, 150, 150, matrix, true);
        }
        canvas.drawBitmap(resizedBitmap, 0.0f, 0.0f, null);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        int d = Math.max(getMeasuredWidth(), getMeasuredHeight()) - 5;
        this.cX = d;
        this.cY = d / 2;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(150, 150);
    }
}
